﻿#ifndef IDADIALOGFRAME_H
#define IDADIALOGFRAME_H

#include <QDialog>
#include <QPointer>
#include <QEventLoop>

#include "API_BaseWidget.h"
#include "IdaPara.h"

#include "IdaMainWindow.h"

class API_BASEWIDGET IdaDialogFrame : public QDialog
{
    Q_OBJECT
public:
    IdaDialogFrame(QWidget* parent = Q_NULLPTR);
    ~IdaDialogFrame();

    /// @brief 显示窗体框架
    inline void showWindowFrame()
    {
        m_windowFrame->show();
    }

    /// @brief 隐藏窗体框架
    inline void hideWindowFrame()
    {
        m_windowFrame->hide();
    }

    /// @brief 显示窗体
    void showWindow();

    /// @brief 隐藏窗体
    void hideWindow();

    /// @brief 阻塞显示窗体
    int execWindow();

    /// @brief 关闭窗体
    /// @param status 状态
    void closeWindow(int status = 0);

    /// @brief 设置标题栏文本
    /// @param text 文本
    void setWindowTitle(QString text);

    /// @brief 设置不关闭窗体。点击关闭按钮后只隐藏窗体，不关闭
    /// @param isNoClose 不关闭窗体
    void setNoCloseWindow(bool isNoClose = true);

signals:

    /// @brief 窗体状态变化
    /// @param windowState 窗体状态
    void signal_windowStateChange(Qt::WindowStates windowState);

    /// @brief 窗体关闭按钮被点击
    /// @param isAllowClose 是否允许窗体被关闭
    void signal_readyCloseDialog(bool& isAllowClose);

protected:
    void setWindowModality(Qt::WindowModality windowModality);

    void setWindowButtonType(BaseWidget::ETitleBars buttonType);

    void setWindowFlags(Qt::WindowFlags flags);

    void setWindowSize(int width, int height);

    void setAttribute(Qt::WidgetAttribute attribute, bool on = true);

protected slots:

    void reject() override;

    void accept() override;

private slots:

    void slot_closeButtonClick();

private:
    /// @brief 初始化对话框
    void initDialog();

private:
    QPointer<IdaMainWindow> m_windowFrame; // 窗体框架
    QEventLoop m_loop;                     // 循环事件
    bool m_isNoCloseWindow;                // 是否不关闭窗体
};
#endif // IDADIALOGFRAME_H
